<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/

Route::get('/', ['as'=> 'home', 'uses' => 'HomeController@showHome']);

Route::get('user/profile', array('as' => 'profile', 'uses' => 'UserController@showProfile'));

Route::get('relato/{slug}/{id}', ['as'=> 'relato', 'uses'=>'RelatoController@showRelato']);

Route::get('objeto/{slug}/{id}', ['as'=> 'objeto', 'uses'=>'ObjetoController@showObjeto']);

Route::get('apartment/{fecha}/{id}', ['as'=> 'apartment', 'uses'=>'ApartmentController@showApartment']);

Route::get('page/{slug}/{id}', ['as'=> 'page', 'uses'=>'PageController@showPage']);

// ../relatos/categoria/interiorismo/3
Route::get('relatos/categoria/{slug}/{id}', ['before' => 'anon', 'as'=> 'categoria_rel', 'uses' => 'RelatoController@showRelatos']);

Route::get('objetos/categoria/{slug}/{id}', ['before' => 'anon', 'as'=> 'categoria_obj', 'uses' => 'ObjetoController@showObjetos']);

//Route::get('header', function(){
//    return View::make('header');
//});



/** ------------------------------------------
 *  Admin Routes
 *  ------------------------------------------
 */

Route::group(['prefix' => 'admin', 'before' => 'auth'], function()
{
    Route::get('escritorio', ['as' => 'adminEscritorio', 'uses' => 'AdminEscritorioController@showEscritorio']);
//------------------------------------------
//Routes::resource
//------------------------------------------

//------------------------------------------------------------------------------
//HTTP Verb | Path (URL)    |     Action (Method) |  Route Name    |  View file
//------------------------------------------------------------------------------
//GET         /objetos              index()          objetos.index      Si
//POST        /objetos              store()          objetos.store      No
//GET         /objetos/create       create()         objetos.create     Si
//GET         /objetos/{id}         show()           objetos.show       Si
//PUT/PATCH   /objetos/{id}         update()         objetos.update     No
//DELETE      /objetos/{id}         destroy()        objetos.destroy    No
//GET         /objetos/{id}/edit    edit()           objetos.edit       Si
    
//------------------------------------------------------------------------------
//PUT         /objetos              index()          objetos.index      Si


    //////////// 
    // Pages //    
    ///////////
    Route::resource('pages', 'AdminPageController', ['only' => ['index', 'edit', 'update']]);
    //Route::post('pages/ordenar', ['as' => 'adminOrderPages', 'uses' => 'AdminPageController@ordenar']);
    
    //////////// 
    //Objetos//    
    ///////////
    
    Route::resource('objetos', 'AdminObjetoController');
    Route::post('objetos/ordenar', ['as' => 'adminOrderObjetos', 'uses' => 'AdminObjetoController@ordenar']);
    
    ////////////// 
    //Apartments//    
    //////////////
    
    Route::resource('apartments', 'AdminApartmentController');

//    app
//    ---views
//    ------admin
//    ---------objetos
//    ------------index.blade.php
//    ------------create.blade.php
//    ------------show.blade.php
//    ------------edit.blade.php

    /////////// 
    //Relatos//    
    ///////////    
    
    Route::resource('relatos', 'AdminRelatoController');
    Route::post('relatos/ordenar', ['as' => 'adminOrderRelatos', 'uses' => 'AdminRelatoController@ordenar']);

    
    /////////// 
    //TagObj //    
    ///////////    
    //Route::resource('tagobjs', 'AdminTagObjController');
    
    Route::resource('tagobjs', 'AdminTagObjController', ['except' => ['show']]);

    /////////// 
    //TagRel //    
    ///////////
    
    Route::resource('tagrels', 'AdminTagRelController', ['except' => ['show']]);
    
    //////////// 
    //Imagenes//    
    ////////////  
    Route::group(['prefix' => 'objeto'], function()
    {
       Route::resource('imagenes', 'AdminImageobjController', ['only' => ['edit', 'update', 'destroy']]);
       Route::post('imagenes/ordenar', 'AdminImageobjController@ordenar');
    });
    
    Route::group(['prefix' => 'apartment'], function()
    {
       Route::resource('imagenes', 'AdminImageapaController', ['only' => ['edit', 'update', 'destroy']]);
       Route::post('imagenes/ordenar', 'AdminImageapaController@ordenar');
    });
    
    Route::group(['prefix' => 'relato'], function()
    {
       Route::resource('imagenes', 'AdminImagerelController', ['only' => ['edit', 'update', 'destroy']]);
       Route::post('imagenes/ordenar', 'AdminImagerelController@ordenar');
    });
    
    Route::group(['prefix' => 'page'], function()
    {
       Route::resource('imagenes', 'AdminImagepageController', ['only' => ['edit', 'update', 'destroy']]);
       Route::post('imagenes/ordenar', 'AdminImagepageController@ordenar');
    });
    
});


///////////// 
//  Users  //    
/////////////

// route to show the login form
Route::get('login', ['uses' => 'AdminUserController@showLogin']);
Route::post('login', ['before' => 'csrf', 'uses' => 'AdminUserController@doLogin']);
Route::get('logout', ['uses' => 'AdminUserController@doLogout']);

// Contact
//Form request:: POST action will trigger to controller
//Route::post('contact_request', 'ContactController@getContactUsForm');

Route::post('contact_request', [
        'before' => 'csrf',
        'uses' =>    'ContactController@getContactUsForm',
    ]);

/*Route::post('contact_request', function(){
    var_dump(Input::all());
    return 'submitted';
});*/